#ifndef __S_MPU9250_H
#define __S_MPU9250_H

#include "i2c.h"
#include "stm32f4xx_hal.h"
#include "S_UART.h"

#define MPU9250Addr 0x68 << 1 //9250的iic地址

#define MPU9250_PWR_MGMT_1 0x6B //复位
#define MPU9250_WHO_AM_I 0x75	//设备id

#define MPU9250_INT_ENABLE 0x38	  //中断
#define MPU9250_GYRO_CONFIG 0x1B  //陀螺仪设置
#define MPU9250_ACCEL_CONFIG 0x1C //加速度计设置
#define MPU9250_CONFIG 0x1A		  //总的设置
#define MPU9250_SMPLRT_DIV 0x19	  //采样率
#define MPU9250_INT_PIN_CFG 0x37

#define MPU9250_XA_OFFSET_H 0x77 //加速度x轴偏零高位地址
#define MPU9250_ACCEL_XOUT_H 0x3B //加速度x轴高位地址

#define MPU9250_XG_OFFSET_H 0x13 //陀螺仪x轴零偏高位地址
#define MPU9250_GYRO_XOUT_H 0x43  //陀螺仪x轴高位地址


#define AK8963Addr 0x0C //AK8963的iic地址

#define AK8963_MAG_WIA 0x00	  //AK8963的id地址
#define AK8963_MAG_OUT_L 0x03 //磁力计输出

//设置低通滤波
#define MPU9250_DLPF_BW_256 0x00
#define MPU9250_DLPF_BW_188 0x01
#define MPU9250_DLPF_BW_98 0x02
#define MPU9250_DLPF_BW_42 0x03
#define MPU9250_DLPF_BW_20 0x04
#define MPU9250_DLPF_BW_10 0x05
#define MPU9250_DLPF_BW_5 0x06

uint8_t mpu9250_init(void);

uint8_t mpu9250_readID(void);

void MPU9250read(int16_t *accdata,int16_t *gyrodata,int16_t *magdata);

uint8_t MPU_i2cWrite(uint8_t slave_addr,uint8_t reg_addr,uint8_t length,uint8_t *data);
uint8_t MPU_i2cRead(uint8_t slave_addr,uint8_t reg_addr,uint8_t length,uint8_t *data);
void mpl_getms(uint32_t *num);
void mpl_printf(const char *fmt, ...);

#endif